use crate::block::Block;

pub struct BlockChain {
    pub blocks: Vec<Block>,
}

impl BlockChain {
    pub fn add_block(&mut self, data: Vec<String>) {
        let pre_block=&self.blocks[self.blocks.len()-1];
        let new_block=Block::new_block(data,pre_block.hash.clone());
        self.blocks.push(new_block);

    }

    fn new_genesis_block() -> Block {
        Block::new_block(vec![String::from("Genesis block")], "".to_string())
    }

    pub fn new_blockchain() -> BlockChain {
        BlockChain{
            blocks: vec![BlockChain::new_genesis_block()]
        }
    }
}